package com.atguigu.spring.tx.xml.dao.impl;

import com.atguigu.spring.tx.xml.dao.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author wk
 * @create 2021-06-03 18:16
 */
@Repository
public class BookDaoImpl implements BookDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Double getPriceByBookId(int bookId) {
        String sql="select price from book where id=?";
        Double price = jdbcTemplate.queryForObject(sql, Double.class, bookId);
        return price;
    }

    @Override
    public void updateStock(int bookId) {
        String sql="update book set stock=stock-1 where id=?";
        jdbcTemplate.update(sql,bookId);
    }

    @Override
    public void UpdateBalance(int userId, Double price) {
        String sql="update account set balance=balance-? where id=?";
        jdbcTemplate.update(sql,price,userId);
    }
}
